package Ioperation;

import book.BookList;

import java.util.Scanner;

public class Deloperation implements Ioperation{
    @Override
    public void work(BookList books) {
        int ret = books.getBooksSize();

        if(ret == 0){
            System.out.println("书架上没有书!");
            return;
        }
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入你要删除的书名:");
        String name = scanner.nextLine();
        int i = 0;
        //创建一个布尔类型的 flg 判断出循环的时候是否 找到了书
        boolean flg = false;
        for (; i < ret; i++) {
            if(name.equals(books.getBooks(i).getName())){
                flg = true;
                break;
            }
        }
        if(flg){
            for(;i < ret - 1;i++){
                books.setBooks(i,books.getBooks(i + 1));
            }
            books.setBooksSize(ret - 1);
            System.out.println("删除成功!");
        }else {
            System.out.println("没有你要删除的书!");
        }
    }
}
